<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>注册页</title>
    <link rel="stylesheet" href="../css/base.css">
    <link rel="stylesheet" href="../css/register.css">
    <!-- 
        外部阿里巴巴矢量图标 
        <link rel="stylesheet" href="http://at.alicdn.com/t/font_2175095_cueku40yyub.css">
    -->
    <!-- 引入外部jQuery CDN文件 -->
    <script src="../js/jquery-3.5.1.min.js"></script>
</head>
<body>
    <div class="register-box">
        <h3>账户注册</h3>
        <!-- Shift+Alt+鼠标选中-多行 -->
        <form id="register-form">
            <div class="user-name">
                <label for="name" class="iconfont iconzhanghao"></label>
                <input id="name" type="text" placeholder="邮箱/用户名/登录手机" autocomplete="off">
            </div>
            <div class="user-pwd">
                <label for="pwd" class="iconfont iconmima"></label>
                <input id="pwd" type="password" placeholder="密码">
                <div class="iconfont iconclose-eye changeStatus"></div>
            </div>
            <div class="user-pwd">
                <label for="confirm-pwd" class="iconfont iconquerenmima"></label>
                <input id="confirm-pwd" type="password" placeholder="确认密码">
                <div class="iconfont iconclose-eye changeStatus"></div>
            </div>
            <button class="user-btn">注册</button>
            <div class="user-action">
                <label>
                    <input type="checkbox" id="check-agreement">已经阅读并同意
                    <a href="#">相关协议</a>
                </label>
                <a href="./login.html">已有账号，立即登录</a>
            </div>
        </form>
    </div>
    <!-- 外部代码 -->
    <script>
        /*
            判断多选框是否选中is(':checked')，若未选择则返回false，选中的状态下返回true
        */
        $(function(){
            $('#register-form').submit(function(){
                /*1、获取输入元素内容*/
                var userAccount = $('#name').val();
                var userPassword = $('#pwd').val();
                var userConfirmPassword = $('#confirm-pwd').val();
                /*2、验证数据是否合法*/
                if(userAccount.replace(/\s+/g,"").length === 0){
                    alert('账号不能为空')
                    /*当不合法时阻止表单提交*/
                    event.preventDefault();
                }else if(userPassword.replace(/\s+/g,"").length === 0){
                    alert('密码不能为空')
                    /*当不合法时阻止表单提交*/
                    event.preventDefault();
                }else if(userConfirmPassword.replace(/\s+/g,"").length === 0){
                    alert('确认密码框不能为空')
                    /*当不合法时阻止表单提交*/
                    event.preventDefault();
                }else if(userConfirmPassword !== userPassword){
                    alert('两次输入密码不一致，请重新确认')
                    /*当不合法时阻止表单提交*/
                    event.preventDefault();
                }else if(!($('#check-agreement').is(':checked'))){
                    alert('请阅读并勾选相关协议')
                    /*当不合法时阻止表单提交*/
                    event.preventDefault();
                }else{
                    alert('表单数据检验完毕，成功提交')
                }
            })
        })
    </script>
    <!-- 公共脚本代码 -->
    <script src="../js/base.js"></script>
</body>
</html>